<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:auth=""
>
<head>
    <th:block th:include="common/head::noXadmin('修改任务')"/>
</head>
<body class="layui-layout layui-layout-admin">
<div class="layui-container">
    <form class="layui-form " th:action="@{/system/task/edit}" method="post">
        <input type="hidden" name="_method" value="PUT">
        <input type="hidden" id="taskId" name="taskId" th:value="${task?.taskId}"/>
        <fieldset class="layui-elem-field layui-field-title">
            <legend>基本信息</legend>
        </fieldset>
        <div class="layui-row layui-col-space30 " style="margin: 0px 30px 0px 30px ">
            <div class="layui-col-md6">
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">任务分组</label>
                    <div class="layui-input-block">
                        <input type="text" name="taskGroup" autocomplete="off" lay-verify="required"
                               placeholder="请输入任务分组"
                               class="layui-input" th:value="${task?.taskGroup}">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label is-required">任务名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="taskName" autocomplete="off" placeholder="请输入任务名称" class="layui-input"
                               required lay-verify="required" th:value="${task?.taskName}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">执行方法</label>
                    <div class="layui-input-block">
                        <input type="text" name="taskClass" lay-verify="required" placeholder="请输入执行方法"
                               autocomplete="off"
                               class="layui-input" th:value="${task?.taskClass}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">执行参数</label>
                    <div class="layui-input-block">
                        <input type="text" name="invokeParam" placeholder="执行参数" autocomplete="off"
                               class="layui-input" lay-verify="required" th:value="${task?.invokeParam}">
                    </div>
                </div>
            </div>
            <div class="layui-col-md6 ">
                <div class="layui-form-item ">
                    <label class="layui-form-label is-required">时区</label>
                    <div class="layui-input-block">
                        <div id="job" class="xm-select-demo"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label is-required">执行时间</label>
                    <div class="layui-input-block">
                        <input type="text" id="taskCron" name="taskCron" th:value="${task?.taskCron}" placeholder="执行时间"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label is-required">状态</label>
                    <div class="layui-input-block">
                        <input type="hidden" id="status" name="status" th:value="${task?.status ==null?1:task?.status}">
                        <input type="checkbox" checked lay-skin="switch" lay-filter="status"
                               lay-text="启用|停用" value="0" th:checked="${task?.status eq 0}">
                    </div>
                </div>


            </div>
        </div>

        <fieldset class="layui-elem-field layui-field-title">
            <legend>其他信息</legend>
        </fieldset>
        <div class="layui-row" style="margin: 0px 30px 0px 30px ">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" name="remark"
                              th:text="${task?.remark}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="ok">保存</button>
                <button type="reset" class="layui-btn layui-btn-danger" lay-filter="close">重置</button>
            </div>
        </div>

    </form>

</div>
<script>

    layui.use(['form', 'layedit', 'laydate', 'xmSelect', "cron"], function () {
        var form = layui.form
            , layer = layui.layer
            , cron = layui.cron
        ;
        cron.render({
            elem: "#taskCron", // 绑定元素
            url:
                "https://www.fastmock.site/mock/58329c0ee61b03d6ce3ba0c1e2f13691/world/cron", // 获取最近运行时间的接口
            value: $("#taskCron").val(), // 默认值
            done: function (cronStr) {
                console.log(cronStr);
                $("#taskCron").val(cronStr);
            },
        });
        let code = '[[${code}]]';
        let message = '[[${message}]]';
        if (code == 200) {
            layer.confirm(message, {
                icon: 1,
                title: '提示',
                btn: ["继续", "关闭"]
            }, function (index) {
                layer.close(index);
            }, function (index) {
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            });
        }
        form.on('switch(status)', function (data) {
            if (data.elem.checked) {
                $("#status").val(0);
            } else {
                $("#status").val(1);
            }
        })
    });
</script>

</body>

</html>
